/*
 * @features: 功能
 * @description: 说明
 * @Date: 2020-08-29 17:10:40
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2020-08-30 19:08:32
 * @LastEditors: judu233
 */

import BuffBase from "../Buff/BuffBase";
import SkillBase from "../Skill/SkillBase";
import Base from "../Base/Base";

/**  
    * @Title : buff管理器
    * @Description : 该类又技能类管理 - 关系： 技能 <-> buff  =  一对多
 **/
export default class BuffManager extends Base {
    /**技能 */
    public skill: SkillBase;

    /**所有Buff */
    public buff: Map<string, BuffBase> = new Map();

    /**正在释放的buff */
    public releaseBuffMap: Map<string, BuffBase> = new Map();

    /**已失效Buff */
    public failureBuffMap: Map<string, BuffBase> = new Map();

    /**初始化buff管理 */
    public initBuffManager(buffList: BuffBase[]) {
        buffList.forEach(buff => {
            this.buff.set(buff.data.id, buff);
        });
    }

    /**使用buff */
    public useBuff(buff: BuffBase) {
        buff.useBuff();
        this.releaseBuffMap.set(buff.data.id, buff);
    }

    /**使用完毕，移除Buff */
    public removeBuff(buff: BuffBase) {
        if (this.releaseBuffMap.delete(buff.data.id))
            this.failureBuffMap.set(buff.data.id, buff);
        else
            cc.warn(`${this.className}移除Buff失败，未找到id:${buff.data.id}, name:${buff.data.name}的buff`);
    }

    /**叠加buff */
    public overlayBuff(buff: BuffBase) { }
}
